Skip to content

Proxy CONNECT custom headers #1774

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 27, 2021
Merged

Proxy CONNECT custom headers #1774

merged 6 commits into from
Mar 27, 2021

Conversation

neket985
Copy link
Contributor

@neket985 neket985 commented Feb 20, 2021

Hello!
I've added an option for custom headers to proxy CONNECT http request at my fork. It solves the issue 1101 (#1101). It worked for me, and I hope, you will add this solution to your project after review.
My solution is simple, and I could miss some details.
Simple implementation is appended to this message.
Will appreciate to read from you :)

If you speak Russian, translation is below.
Здравствуйте!
В данном ответвлении я реализовал возможность добавления кастомных заголовков при отправке http запроса с методом CONNECT на прокси. Issue, заведенное под эту функциональность нашел по ссылке (#1101).
Это решение работает для меня, поэтому я надеюсь, что вы добавите его в каком-то виде к себе в проект.
Мое решение выглядит слишком просто, поэтому я понимаю, что мог не учесть каких-то деталей.
Простая реализация использования функциональности представлена внизу описания.
Буду рад любым комментариям :)

package package.test;

import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpHeaders;
import org.asynchttpclient.*;
import org.asynchttpclient.proxy.ProxyType;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import static org.asynchttpclient.Dsl.*;
import static org.asynchttpclient.Dsl.basicAuthRealm;

public class Test {
    public static void main(String[] args) throws ExecutionException, InterruptedException, IOException {
        AsyncHttpClient client = asyncHttpClient();
        Request request = new RequestBuilder()
                .setMethod("GET")
                .setUrl("https://www.google.com")
                .setProxyServer(
                        proxyServer("proxy.host", 8080)
                                .setProxyType(ProxyType.SOCKS_V5)
                                .setRealm(basicAuthRealm("user", "password").setUsePreemptiveAuth(true))
                                .setCustomHeaders(req -> {
                                        HttpHeaders headers = new DefaultHttpHeaders().clear();
                                        headers.add("Custom-Header", "custom value");
                                        return headers;
                                })
                )
                .build();
        ListenableFuture<Response> response = client.executeRequest(request);
        int status = response.get().getStatusCode();
        System.out.println(status);
        client.close();
    }
}

108594783-036d2680-738d-11eb-85c0-7f86e075bc17

@TomGranot TomGranot merged commit 576decf into AsyncHttpClient:master Mar 27, 2021
@TomGranot
Copy link
Contributor

@neket985 Nice one! Clean and simple. Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants